package com.ecloud.common.web.translate;

import java.util.HashMap;
import java.util.Map;

import com.ecloud.common.base.translate.TranslateSource;

/**
 * 自定义序列化工厂
 *
 * @author LiuGangQiang Create in 2021/08/19
 */
public class CustomSerializeFactory {
    private Map<TranslateSource, ICustomSerialize> serializes;

    /**
     * 初始化
     *
     * @author LiuGangQiang Create in 2021/08/19
     */
    public CustomSerializeFactory() {
        serializes = new HashMap<TranslateSource, ICustomSerialize>();
    }

    /**
     * 根据来源类型构建
     *
     * @author LiuGangQiang Create in 2021/08/19
     * @param source 来源
     * @return {@link ICustomSerialize}
     */
    public ICustomSerialize build(TranslateSource source) {
        return serializes.get(source);
    }

    /**
     * 注册序列化
     *
     * @author LiuGangQiang Create in 2021/08/19
     * @param source    翻译来源
     * @param serialize 序列化
     */
    public void register(TranslateSource source, ICustomSerialize serialize) {
        this.serializes.put(source, serialize);
    }
}
